package com.chenye.service1;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.sleuth.Span;
import org.springframework.cloud.sleuth.Tracer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.client.RestTemplate;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @Auther:chenye
 * @Data:2018/6/25
 * @Description:
 */
@SpringBootApplication
@RestController
@ComponentScan(value="com.chenye.service1")
public class Service1Application {
    private static final Logger log = LoggerFactory.getLogger(Service1Application.class);
    public static void main(String[] args){
        SpringApplication.run(Service1Application.class,args);
    }
    @Autowired
    private Tracer tracer;

    @RequestMapping("/getHi")
//    @NewSpan("service1 span")
    public String getHi(HttpServletRequest request){
        request.getHeaderNames();
        request.getParameterMap();
        log.info("service1 info");
        Span span = tracer.createSpan("service 1 span");
        tracer.addTag("addTag","service 1 tag value");
        tracer.close(span);
        restTemplate.getForObject("http://localhost:8081/callBack",String.class);
        return "i am service 1!";
    }

    @Autowired
    private RestTemplate restTemplate;

    @Bean
    public RestTemplate createRestTemplate(){
        return new RestTemplate();
    }
}
